﻿using strange.extensions.command.impl;
using System;
using System.Collections.Generic;
using UnityEngine;

public class PlayCardCommand:EventCommand
{
    [Inject]
    public RoundModel RoundModel { get; set; }
    [Inject]
    public IntegrationModel IntegrationModel { get; set; }

    public override void Execute()
    {
        PlayCardArgs e = evt.data as PlayCardArgs;
        //判断玩家能不能出牌
        if (e.CharacterType == CharacterType.Player)
        {
            if (e.currentCardType == RoundModel.CurrentCardType && e.currentWeight > RoundModel.CurrentWeight)
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlayCard);
            }
            else if (e.currentCardType == CardType.Boom && RoundModel.CurrentCardType != CardType.Boom)
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlayCard);
            }
            else if (e.currentCardType == CardType.JokerBoom)
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlayCard);
            }
            else if (RoundModel.BiggestCharacter == CharacterType.Player)
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlayCard);
            }
            else
            {
                Debug.Log("不合法的出牌");
                return;
            }
        }
        //如果是炸弹 积分翻倍
        if (e.currentCardType == CardType.Boom || e.currentCardType == CardType.JokerBoom)
        {
            IntegrationModel.Multiply *= 2;
        }
        //更新回合信息
        RoundModel.CurrentCardType = e.currentCardType;
        RoundModel.CurrentCharacter = e.CharacterType;
        RoundModel.CurrentLength = e.currentLength;
        RoundModel.CurrentWeight = e.currentWeight;
        RoundModel.BiggestCharacter = e.CharacterType;//更新最大出牌者
        RoundModel.Turn();
    }
}

